<template>
	<div class="home">
    <div class="banner-box">
      <u-swiper
          indicator
          previousMargin="30"
          nextMargin="30"
          indicatorMode="line"
          circular
          effect3d
          radius="5"
          :list="bannerList"  img-mode="scaleToFill" :height="280" @click="clickBanner"></u-swiper>
    </div>
    <div class="content">
      <div class="menu">
        <u-row gutter="8">
          <u-col span="3" v-for="item in menuList" :key="item.id">
            <div class="menu-item" @click="toCategory(item.id)">
              <image class="img" :src="item.image" alt=""/>
              <div class="menu-name">{{ item.name }}</div>
            </div>
          </u-col>
        </u-row>
      </div>
    </div>
    <RecommendList />
  </div>
</template>

<script>
import RecommendList from "./recommendList.vue";
	export default {
    components: {
      RecommendList,
    },
		data() {
			return {
        bannerList: [],
        noticeList: [
          '学习平台上线了！',
        ],
        recommendList: [

        ],
        menuList: [

        ]
			}
		},
    onShow() {

    },
		onLoad() {
      // 获取banner
      this.$api.bannerList().then(res => {
        this.bannerList = res
      })
      // 获取分类
      this.$api.categoryList().then(res => {
        this.menuList = res.map(el => {
          return {
            image:  el.image,
            name: el.name,
            id: el.id
          }
        })
      })
		},
		methods: {
      // 跳转到分类
      toCategory(id) {
        uni.switchTab({
          url: '/pages/category/category?id=' + id
        })
      },
      // 点击banner
      clickBanner(e) {
        const item = this.bannerList[e]
        if (item) {
          uni.navigateTo({
            url: '/pages/index/banner?id=' + item.id
          })
        }
      }
		}
	}
</script>

<style lang="scss">
.home {
  padding: 24rpx;
  padding-bottom: 120rpx;
  .top {
    background-repeat: no-repeat;
    background-size: cover;
    width: 100%;
    height: 125rpx;
    position: fixed;
    top: 0;
    z-index: 9;
    background-image: url("@/static/top.png");
    .top-title {
      position:absolute;
      top: 30rpx;
      width: 100%;
      text-align: center;
      font-size: 36rpx;
      color: #FFFFFF;
      font-weight: bold;
    }
  }

  .notice {
    background-color: #fff;
    margin-bottom: 30rpx;
  }
  .tips {
    background-color: #fff;
    padding: 30rpx;
    margin-bottom: 30rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 24rpx;
    color: #8d8e99;
    .tip-item {
      display: flex;
      align-items: center;
      .img {
        width: 36rpx;
        height: 36rpx;
      }
      .text {
        margin-left: 20rpx;
      }
    }
  }
  .content {
    background-color: #ffffff;
    padding: 20rpx;
    border-radius: 24rpx;
    margin: 24rpx 0;
    .img {
      width: 100%;
    }
  }
  .banner-box {
    width: 100%;
    height: 280rpx;
    overflow: hidden;
  }
    .menu {
      background-color: #fff;
      border-radius: 24rpx;
    }
  .menu-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    .img {
      width: 100rpx;
      height: 100rpx;
      border-radius: 50%;
      margin-bottom: 24rpx;
    }
    .menu-name {
      font-size: 26rpx;
      color: #303133;
    }
  }
}
</style>
